<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>发布志愿活动 - 志愿服务管理系统</title>
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- Font Awesome -->
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
  <style>
    :root {
      --primary-color: #337ab7;
      --hover-color: #286090;
      --bg-gradient: linear-gradient(145deg, var(--primary-color), var(--hover-color));
      --shadow: 0 2px 10px rgba(0,0,0,0.1);
      --transition: all 0.3s ease;
      --border-radius: 10px;
    }

    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
      min-height: 100vh;
      padding: 2rem 0;
    }

    .container {
      max-width: 800px;
    }

    .card {
      background: white;
      border-radius: var(--border-radius);
      box-shadow: var(--shadow);
      border: none;
      overflow: hidden;
    }

    .card-header {
      background: var(--bg-gradient);
      color: white;
      padding: 1.5rem;
      border-bottom: none;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .card-header h2 {
      margin: 0;
      font-size: 1.5rem;
      font-weight: 600;
    }

    .card-body {
      padding: 2rem;
    }

    .form-group {
      margin-bottom: 1.5rem;
      position: relative;
    }

    .form-label {
      font-weight: 500;
      color: #495057;
      margin-bottom: 0.5rem;
    }

    .form-control {
      border-radius: 8px;
      padding: 0.75rem 1rem;
      border: 2px solid #e9ecef;
      transition: var(--transition);
    }

    .form-control:focus {
      border-color: var(--primary-color);
      box-shadow: 0 0 0 0.2rem rgba(51, 122, 183, 0.25);
    }

    .input-group-text {
      background-color: #f8f9fa;
      border: 2px solid #e9ecef;
      border-radius: 8px;
    }

    .btn-submit {
      background: var(--bg-gradient);
      color: white;
      padding: 1rem 2rem;
      border: none;
      border-radius: 8px;
      font-weight: 500;
      width: 100%;
      transition: var(--transition);
    }

    .btn-submit:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow);
    }

    .btn-back {
      color: white;
      text-decoration: none;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      transition: var(--transition);
    }

    .btn-back:hover {
      color: rgba(255, 255, 255, 0.8);
      transform: translateX(-5px);
    }

    textarea.form-control {
      min-height: 120px;
      resize: vertical;
    }

    .input-icon {
      position: absolute;
      right: 1rem;
      top: 2.75rem;
      color: #6c757d;
    }

    .alert {
      border-radius: var(--border-radius);
      margin-bottom: 1rem;
    }

    @media (max-width: 768px) {
      .container {
        padding: 0 15px;
      }

      .card-header {
        padding: 1rem;
      }

      .card-body {
        padding: 1.5rem;
      }
    }
  </style>
</head>
<body>
<div class="container">
  <div class="card">
    <div class="card-header">
      <a href="#" th:href="@{/toActivityList}" class="btn-back">
        <i class="fas fa-arrow-left"></i>
        <span>查看活动列表</span>
      </a>
      <h2><i class="fas fa-calendar-plus me-2"></i>发布志愿活动</h2>
    </div>

    <div class="card-body">
      <form th:action="@{/toAddActivity}" method="post" enctype="multipart/form-data" id="activityForm">
        <div class="form-group">
          <label class="form-label" for="activityName">活动名称</label>
          <input type="text" class="form-control" id="activityName" name="activityName"
                 required placeholder="请输入活动名称">
          <i class="fas fa-heading input-icon"></i>
        </div>

        <div class="form-group">
          <label class="form-label" for="activityAddress">活动地点</label>
          <input type="text" class="form-control" id="activityAddress" name="activityAddress"
                 required placeholder="请输入活动地点">
          <i class="fas fa-map-marker-alt input-icon"></i>
        </div>

        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label" for="startTime">活动时间</label>
              <input type="datetime-local" class="form-control" id="startTime" name="startTime" required>
              <i class="fas fa-clock input-icon"></i>
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label" for="sustain">活动持续时间（小时）</label>
              <input type="number" class="form-control" id="sustain" name="sustain"
                     required min="1" placeholder="请输入持续时间">
              <i class="fas fa-hourglass-half input-icon"></i>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="form-label" for="number">可报名人数</label>
          <input type="number" class="form-control" id="number" name="number"
                 required min="1" placeholder="请输入可报名人数">
          <i class="fas fa-users input-icon"></i>
        </div>

        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label" for="enlistsStart">报名开始时间</label>
              <input type="datetime-local" class="form-control" id="enlistsStart" name="enlistsStart" required>
              <i class="fas fa-play input-icon"></i>
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label class="form-label" for="enlistsEnd">报名截止时间</label>
              <input type="datetime-local" class="form-control" id="enlistsEnd" name="enlistsEnd" required>
              <i class="fas fa-stop input-icon"></i>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="form-label" for="introduce">活动介绍</label>
          <textarea class="form-control" id="introduce" name="introduce"
                    required placeholder="请详细描述活动内容、要求等信息"></textarea>
        </div>

        <div class="form-group mb-0">
          <button type="submit" class="btn btn-submit">
            <i class="fas fa-paper-plane me-2"></i>发布活动
          </button>
        </div>
      </form>
    </div>
  </div>
</div>

<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

<script>
  // 表单验证
  document.getElementById('activityForm').addEventListener('submit', function(e) {
    const startTime = new Date(document.getElementById('startTime').value);
    const enlistsStart = new Date(document.getElementById('enlistsStart').value);
    const enlistsEnd = new Date(document.getElementById('enlistsEnd').value);
    const now = new Date();

    if (enlistsStart >= enlistsEnd) {
      e.preventDefault();
      alert('报名开始时间必须早于报名截止时间！');
      return;
    }

    if (enlistsEnd >= startTime) {
      e.preventDefault();
      alert('报名截止时间必须早于活动开始时间！');
      return;
    }

    if (enlistsStart < now) {
      e.preventDefault();
      alert('报名开始时间不能早于当前时间！');
      return;
    }
  });

  // 自动填充当前时间
  window.addEventListener('load', function() {
    const now = new Date();
    const offset = now.getTimezoneOffset() * 60000;
    const localISOTime = (new Date(now - offset)).toISOString().slice(0, 16);

    document.getElementById('enlistsStart').min = localISOTime;
    document.getElementById('enlistsEnd').min = localISOTime;
    document.getElementById('startTime').min = localISOTime;
  });
</script>
</body>
</html>